package com.example.springmvc.demos.web;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.management.Query;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * url参数类型  ?后面
 * <p>
 * test1-test4 url传参 ?后面的参数 http://127.0.0.1:8080/url/test4?name=zkz&age=53&id=44
 */
@Controller
@RequestMapping("/url")
public class UrlParamController {

    @RequestMapping("/test1")
    @ResponseBody
    public String test1(@RequestParam(name = "name") String name, @RequestParam(name = "id") int id) {
        return name + "_" + id;
    }


    @RequestMapping("/test2")
    @ResponseBody
    public String test2(String name, int id) {
        return name + "_" + id;
    }

    @GetMapping("/test3")
    @ResponseBody
    public String test3(UserDemo user) {
        return user.getName() + "_" + user.getId();
    }

    @GetMapping("/test4")
    @ResponseBody
    public String test4(HttpServletRequest request) {
        String name = request.getParameter("name");
        String id = request.getParameter("id");
        return name + "_" + id;
    }

    @PostMapping("/test5")
    @ResponseBody
    public String test5(@RequestParam(name = "name") String name, @RequestParam(name = "id") int id) {
        return name + "_" + id;
    }

    @PostMapping("/test6")
    @ResponseBody
    public String test6(UserDemo user) {
        return user.getName() + "_" + user.getId();
    }
    @PostMapping("/test7")
    @ResponseBody
    public String test7( @RequestParam(name = "list") List<String> stringList) {
        return stringList.toString();
    }
    @PostMapping("/test8")
    @ResponseBody
    public String test8( @RequestParam(name="user") List<UserDemo> userDemoList) {
        return userDemoList.toString();
    }
}
